package org.agridata.akvisualization.controller.jiage;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.agridata.akvisualization.doMain.entity.PriceTrend;
import org.agridata.akvisualization.doMain.vo.PriceTrendVo;
import org.agridata.akvisualization.result.Result;
import org.agridata.akvisualization.service.PriceTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author: yxc
 * @date: 2024/2/21 15:58
 * @Description: 屠宰价格走势
 */
@RestController
@RequestMapping("/animalSaveCrop")
@Api(tags = "屠宰价格走势")
public class PriceTrendController {

    @Autowired
    PriceTrendService priceTrendService;

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("屠宰价格走势数据导入")
    @PostMapping("priceTrendImport")
    public Result priceTrendImport(@RequestPart("file") MultipartFile file, String dates, String monthly){
        try {
            List<PriceTrend> memberList = EasyExcel.read(file.getInputStream())
                    .head(PriceTrend.class)
                    .sheet()
                    .doReadSync();
            return priceTrendService.importPriceTrend(memberList,dates,monthly);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.fail("出现异常");
        }
    }

    @ApiOperation("屠宰价格走势表格数据")
    @GetMapping("/getPriceTrendList")
    public Result getPriceTrendList(String data,String monthly,Long pageNum,Long pageSize){
        try {
            Page<PriceTrendVo> pageData = priceTrendService.getPriceTrendList(data,monthly,pageNum,pageSize);
            return Result.ok(pageData);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败");
        }
    }

    @ApiOperation("首页屠宰价格走势展示")
    @PostMapping("/perMensem")
    public Result pricePerMensem(){
        return priceTrendService.pricePerMensems();
    }

}
